package service.impl;

import bean.Role;
import bean.Users;
import dao.impl.RoleDaoImpl;
import dao.impl.UsersDaoImpl;
import service.UsersService;

import java.util.List;

public class UsersServiceImpl implements UsersService {

    UsersDaoImpl dao = new UsersDaoImpl();


    @Override
    public Users getUser(String loginname, String password) {
        Users user = dao.getUser(loginname, password);
        RoleDaoImpl rd = new RoleDaoImpl();
        if (user==null){
            return null;
        }else{
            int roleid = user.getRoleid();
            Role role = rd.findRoleById(roleid);
            user.setRole(role);
            return  user;
        }
    }

    @Override
    public List<Users> getUserList(int index, int pagesize) {
        return dao.getUserList(index, pagesize);
    }

    @Override
    public int getTotal() {
        return dao.getTotal();
    }

    @Override
    public int addUser(Users users) {
        return dao.addUser(users);
    }

    @Override
    public List<Role> getRoleList() {
        return dao.getRoleList();
    }

    @Override
    public Users findUserById(int userid) {
        return dao.findUserById(userid);
    }

    @Override
    public int updateUserById(Users users) {
        return dao.updateUserById(users);
    }

    @Override
    public int deleteUserById(int userid) {
        return dao.deleteUserById(userid);
    }

}